package cn.stylefeng.guns.modular.rest.fruits;

import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.core.util.DateUtil;
import cn.stylefeng.guns.modular.fruits.entity.FruitsOrderOut;
import cn.stylefeng.guns.modular.fruits.entity.FruitsOrderPut;
import cn.stylefeng.guns.modular.fruits.entity.FruitsPacking;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsAllocationParam;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsBasicChannelParam;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsBasicCustomerParam;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsBasicGoodsInstallParam;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsBasicGoodsParam;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsOrderOutDetailedParam;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsOrderOutParam;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsOrderPutParam;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsPackingParam;
import cn.stylefeng.guns.modular.fruits.model.params.FruitsStorageStockParam;
import cn.stylefeng.guns.modular.fruits.model.result.FruitsBasicChannelResult;
import cn.stylefeng.guns.modular.fruits.model.result.FruitsBasicCustomerResult;
import cn.stylefeng.guns.modular.fruits.model.result.FruitsBasicGoodsInstallResult;
import cn.stylefeng.guns.modular.fruits.model.result.FruitsBasicGoodsResult;
import cn.stylefeng.guns.modular.fruits.model.result.FruitsOrderOutDetailedResult;
import cn.stylefeng.guns.modular.fruits.model.result.FruitsStorageStockResult;
import cn.stylefeng.guns.modular.fruits.service.FruitsAllocationService;
import cn.stylefeng.guns.modular.fruits.service.FruitsBasicChannelService;
import cn.stylefeng.guns.modular.fruits.service.FruitsBasicCustomerService;
import cn.stylefeng.guns.modular.fruits.service.FruitsBasicGoodsInstallService;
import cn.stylefeng.guns.modular.fruits.service.FruitsBasicGoodsService;
import cn.stylefeng.guns.modular.fruits.service.FruitsOrderOutDetailedService;
import cn.stylefeng.guns.modular.fruits.service.FruitsOrderOutService;
import cn.stylefeng.guns.modular.fruits.service.FruitsOrderPutService;
import cn.stylefeng.guns.modular.fruits.service.FruitsPackingService;
import cn.stylefeng.guns.modular.fruits.service.FruitsStorageStockService;
import cn.stylefeng.guns.modular.rest.aop.UserAop;
import cn.stylefeng.guns.sys.modular.system.entity.User;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import cn.stylefeng.roses.core.util.ToolUtil;

/**
 * 智慧果园
 */
@Controller
@RequestMapping("/rest/fruits")
public class restFruitsController extends BaseController {

    @Autowired
    private UserAop userAop;

    @Autowired
    private FruitsBasicGoodsService fruitsBasicGoodsService;

    @Autowired
    private FruitsBasicGoodsInstallService fruitsBasicGoodsInstallService;

    @Autowired
    private FruitsOrderPutService fruitsOrderPutService;

    @Autowired
    private FruitsStorageStockService fruitsStorageStockService;
    
    private Lock lock = new ReentrantLock();
    
    /**
     *查询商品
     */
    @RequestMapping("/findgoodslist")
    @ResponseBody
    public ResponseData findgoodslist() {
    	User user = userAop.getUser();
    	FruitsBasicGoodsParam goodsParam = new FruitsBasicGoodsParam();
    	goodsParam.setDeptId(user.getDeptId());
    	List<FruitsBasicGoodsResult> list = fruitsBasicGoodsService.findListBySpec(goodsParam,user.getOperateId());
        return ResponseData.success(list);
    }
    
    /**
     *查询商品
     */
    @RequestMapping("/findgoodsInstalllist")
    @ResponseBody
    public ResponseData findgoodsInstalllist(FruitsBasicGoodsInstallParam basicGoodsInstallParam) {
    	User user = userAop.getUser();
    	basicGoodsInstallParam.setDeptId(user.getDeptId());
    	List<FruitsBasicGoodsInstallResult> list = fruitsBasicGoodsInstallService.findListBySpec(basicGoodsInstallParam,user.getOperateId());
        return ResponseData.success(list);
    }

    /**
     * 撤销采摘入库
     */
    @RequestMapping("/revoke_rk")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class,timeout=50)
    public ResponseData revoke_rk(FruitsOrderPutParam fruitsOrderPutParam) {
    	User user = userAop.getUser();
    	FruitsOrderPut fruitsOrderPut = fruitsOrderPutService.getById(fruitsOrderPutParam.getId());
    	if(!fruitsOrderPut.getStates().equals("RECEIVED")) {
    		return ResponseData.error("入库单状态已改变！");
    	}
    	fruitsOrderPutParam.setStates("已撤销");
    	fruitsOrderPutService.update(fruitsOrderPutParam);//更新入库单状态
    	
    	FruitsStorageStockParam fruitsStorageStockParam = new FruitsStorageStockParam();
    	fruitsStorageStockParam.setStockstate("在库");
    	fruitsStorageStockParam.setProducetime(fruitsOrderPut.getProducetime());
    	fruitsStorageStockParam.setWarehouseName(fruitsOrderPut.getWarehouseName());
    	fruitsStorageStockParam.setGoodsId(fruitsOrderPut.getGoodsId());
    	fruitsStorageStockParam.setDeptId(user.getDeptId());
    	FruitsStorageStockResult fruitsStorageStockResult = fruitsStorageStockService.findBySpec(fruitsStorageStockParam,user.getOperateId());
    	if(fruitsStorageStockResult == null) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
    		return ResponseData.error("库存已发生变动！");
    	}
    	BigDecimal weight = new BigDecimal(fruitsOrderPut.getWeight());//入库单  重量
    	BigDecimal sweight = new BigDecimal(fruitsStorageStockResult.getWeight());//入库单  重量
    	if(sweight.compareTo(weight) == 1) {//如果库存  大于撤回入库重量
    		sweight = sweight.subtract(weight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
    		FruitsStorageStockParam updateStockParam = new FruitsStorageStockParam();
    		updateStockParam.setId(fruitsStorageStockResult.getId());
    		updateStockParam.setWeight(sweight.toString());
    		fruitsStorageStockService.update(updateStockParam);//扣减库存重量
    	} else if(sweight.compareTo(weight) == 0) {
    		FruitsStorageStockParam updateStockParam = new FruitsStorageStockParam();
    		updateStockParam.setId(fruitsStorageStockResult.getId());
    		updateStockParam.setWeight("0");
    		fruitsStorageStockService.update(updateStockParam);//扣减库存重量
    	} else {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
    		return ResponseData.error("库存已发生变动！");
    	}
        return ResponseData.success();
    }
    
    /**
     *新增采摘入库
     */
    @RequestMapping("/addItem")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class,timeout=50)
    public ResponseData addItem(FruitsOrderPutParam fruitsOrderPutParam) {
    	User user = userAop.getUser();
		lock.lock();//获取锁
		try {
	    	FruitsBasicGoodsParam fruitsBasicGoodsParam = new FruitsBasicGoodsParam();
	    	fruitsBasicGoodsParam.setDeptId(user.getDeptId());
	    	fruitsBasicGoodsParam.setGoodsName(fruitsOrderPutParam.getGoodsName());
	    	FruitsBasicGoodsResult basicGoodsResult = fruitsBasicGoodsService.findBySpec(fruitsBasicGoodsParam,user.getOperateId());
	    	
	    	FruitsOrderPutParam to = new FruitsOrderPutParam();
	    	to.setTimes(DateUtil.getDate());
	    	to.setDeptId(user.getDeptId());
	    	int count = fruitsOrderPutService.countBydate(to,user.getOperateId());
	    	
	    	fruitsOrderPutParam.setStates("RECEIVED");
	    	fruitsOrderPutParam.setPutNumber("R"+DateUtil.getDateBch()+fruitsOrderPutParam.getUserNumber()+(count+1));//时间+采摘人编码+今日条数+1
	    	fruitsOrderPutParam.setGoodsId(Long.parseLong(basicGoodsResult.getId().toString()));
	    	fruitsOrderPutParam.setProducetime(DateUtil.getDate());
	    	fruitsOrderPutParam.setDeptId(user.getDeptId());
	    	fruitsOrderPutService.add(fruitsOrderPutParam);
	    	
	    	FruitsStorageStockParam fruitsStorageStockParam = new FruitsStorageStockParam();
	    	fruitsStorageStockParam.setStockstate("在库");
	    	fruitsStorageStockParam.setProducetime(DateUtil.getDate());
	    	fruitsStorageStockParam.setWarehouseName(fruitsOrderPutParam.getWarehouseName());
	    	fruitsStorageStockParam.setGoodsId(fruitsOrderPutParam.getGoodsId());
	    	fruitsStorageStockParam.setDeptId(user.getDeptId());
	    	FruitsStorageStockResult fruitsStorageStockResult = fruitsStorageStockService.findBySpec(fruitsStorageStockParam,user.getOperateId());
	    	if(fruitsStorageStockResult != null) {
	    		BigDecimal sweight = new BigDecimal(fruitsStorageStockResult.getWeight());
	    		BigDecimal weight = new BigDecimal(fruitsOrderPutParam.getWeight());
	    		BigDecimal newweight = sweight.add(weight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    		fruitsStorageStockParam.setId(fruitsStorageStockResult.getId());
	    		fruitsStorageStockParam.setWeight(newweight.toString());
	    		fruitsStorageStockService.update(fruitsStorageStockParam);
	    	} else {
	    		fruitsStorageStockParam.setGoodsName(fruitsOrderPutParam.getGoodsName());
	    		fruitsStorageStockParam.setWeight(fruitsOrderPutParam.getWeight());
	    		fruitsStorageStockService.add(fruitsStorageStockParam);
	    	}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			lock.unlock();//释放锁
		}
        return ResponseData.success();
    }
    
    /**
     *查询加工仓、次果仓、废果仓
     *仓库库存
     */
    @RequestMapping("/findStorageStockSumBySpec")
    @ResponseBody
    public ResponseData findStorageStockSumBySpec(FruitsStorageStockParam fruitsStorageStockParam) {
    	User user = userAop.getUser();
    	fruitsStorageStockParam.setDeptId(user.getDeptId());
    	fruitsStorageStockParam.setStockstate("在库");
    	List<FruitsStorageStockResult> list = fruitsStorageStockService.findStorageStockSumBySpec(fruitsStorageStockParam,user.getOperateId());
        return ResponseData.success(list);
    }
    
    /**
     *查询直发仓、次果仓、废果仓
     *仓库库存
     */
    @RequestMapping("/findStorageStockSumBySpec2")
    @ResponseBody
    public ResponseData findStorageStockSumBySpec2(FruitsStorageStockParam fruitsStorageStockParam) {
    	User user = userAop.getUser();
    	fruitsStorageStockParam.setDeptId(user.getDeptId());
    	fruitsStorageStockParam.setStockstate("在库");
    	List<FruitsStorageStockResult> list = fruitsStorageStockService.findStorageStockSumBySpec2(fruitsStorageStockParam,user.getOperateId());
        return ResponseData.success(list);
    }
    
    /**
     *查询
     *仓库库存
     */
    @RequestMapping("/findStorageStockSum")
    @ResponseBody
    public ResponseData findStorageStockSum(FruitsStorageStockParam fruitsStorageStockParam) {
    	User user = userAop.getUser();
    	fruitsStorageStockParam.setDeptId(user.getDeptId());
    	fruitsStorageStockParam.setStockstate("在库");
    	List<FruitsStorageStockResult> list = fruitsStorageStockService.findStorageStockSum(fruitsStorageStockParam);
        return ResponseData.success(list);
    }

    /**
     * 查询加工仓 列表
     */
    @ResponseBody
    @RequestMapping("/findJiagongcangPagelist")
    public LayuiPageInfo findJiagongcangPagelist(FruitsOrderPutParam fruitsOrderPutParam) {
    	User user = userAop.getUser();
    	fruitsOrderPutParam.setDeptId(user.getDeptId());
        return this.fruitsOrderPutService.findJiagongcangPagelist(fruitsOrderPutParam,user.getOperateId());
    }

    /**
     * 查询直发仓 列表
     */
    @ResponseBody
    @RequestMapping("/findzhifacangPagelist")
    public LayuiPageInfo findzhifacangPagelist(FruitsOrderPutParam fruitsOrderPutParam) {
    	User user = userAop.getUser();
    	fruitsOrderPutParam.setDeptId(user.getDeptId());
        return this.fruitsOrderPutService.findzhifacangPagelist(fruitsOrderPutParam,user.getOperateId());
    }

    /**
     * 查询直发仓 出库 列表
     */
    @ResponseBody
    @RequestMapping("/findzhifacangOutPagelist")
    public LayuiPageInfo findzhifacangOutPagelist(FruitsOrderOutParam fruitsOrderOutParam) {
    	User user = userAop.getUser();
    	fruitsOrderOutParam.setDeptId(user.getDeptId());
        return this.fruitsOrderOutService.findzhifacangOutPagelist(fruitsOrderOutParam,user.getOperateId());
    }

    /**
     * 查询直发仓 出库明细 列表
     */
    @ResponseBody
    @RequestMapping("/findzhifacangOutDetailedlist")
    public ResponseData findzhifacangOutDetailedlist(FruitsOrderOutDetailedParam fruitsOrderOutDetailedParam) {
    	return ResponseData.success(fruitsOrderOutDetailedService.findListBySpec(fruitsOrderOutDetailedParam));
    }

    @Autowired
    private FruitsBasicCustomerService fruitsBasicCustomerService;

    @Autowired
    private FruitsPackingService fruitsPackingService;
    
    /**
     * 撤销 成品包装
     */
    @ResponseBody
    @RequestMapping("/revoke_packing")
	@Transactional(rollbackFor = Exception.class,timeout=50)
    public ResponseData revoke_packing(FruitsPackingParam fruitsPackingParam) {
    	User user = userAop.getUser();
    	FruitsPacking fruitsPacking = fruitsPackingService.getById(fruitsPackingParam.getId());
    	if(!fruitsPacking.getStates().equals("RECEIVED")) {
    		return ResponseData.error("状态已发生变化！");
    	}
    	fruitsPackingParam.setStates("已撤销");
    	fruitsPackingService.update(fruitsPackingParam);
    	
    	FruitsStorageStockParam fruitsStorageStockParam = new FruitsStorageStockParam();
    	fruitsStorageStockParam.setStockstate("在库");
    	fruitsStorageStockParam.setWarehouseName("加工仓");
    	fruitsStorageStockParam.setGoodsId(fruitsPacking.getGoodsId());
    	fruitsStorageStockParam.setProducetime(fruitsPacking.getProducetime());
    	fruitsStorageStockParam.setDeptId(user.getDeptId());
    	FruitsStorageStockResult fruitsStorageStockResult = fruitsStorageStockService.findBySpec(fruitsStorageStockParam,user.getOperateId());
    	if(fruitsStorageStockResult == null) {
    		fruitsStorageStockParam.setGoodsName(fruitsPacking.getGoodsName());
    		fruitsStorageStockParam.setWeight(fruitsPacking.getNweight());
    		fruitsStorageStockService.add(fruitsStorageStockParam);
    	} else {
    		BigDecimal weight = new BigDecimal(fruitsPacking.getNweight());
    		BigDecimal sweight = new BigDecimal(fruitsStorageStockResult.getWeight());
    		sweight = sweight.add(weight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
    		FruitsStorageStockParam updateStockParam = new FruitsStorageStockParam();
    		updateStockParam.setId(fruitsStorageStockResult.getId());
    		updateStockParam.setWeight(sweight.toString());
    		fruitsStorageStockService.update(updateStockParam);
    	}
    	
    	FruitsStorageStockParam fruitsStorageStockParam2 = new FruitsStorageStockParam();
    	fruitsStorageStockParam2.setStockstate("在库");
    	fruitsStorageStockParam2.setWarehouseName("成品仓");
    	fruitsStorageStockParam2.setPositionNumber(fruitsPacking.getPositionNumber());
    	fruitsStorageStockParam2.setGoodsId(fruitsPacking.getGoodsId());
    	fruitsStorageStockParam2.setGrades(fruitsPacking.getGrades());
    	fruitsStorageStockParam2.setCaseWeightOne(fruitsPacking.getCaseWeightOne());
    	fruitsStorageStockParam2.setProducetime(fruitsPacking.getProducetime());
    	fruitsStorageStockParam2.setDeptId(user.getDeptId());
    	FruitsStorageStockResult fruitsStorageStockResult2 = fruitsStorageStockService.findBySpecByPositionNumber(fruitsStorageStockParam2,user.getOperateId());
    	if(fruitsStorageStockResult2 != null) {
    		BigDecimal gweight = new BigDecimal(fruitsPacking.getGweight());//包装毛重
    		BigDecimal nweight = new BigDecimal(fruitsPacking.getNweight());//包装净重
    		BigDecimal nums = new BigDecimal(fruitsPacking.getNums());//包装数量
    		BigDecimal csnums = new BigDecimal(fruitsStorageStockResult2.getNums());//库存数量
    		if(csnums.compareTo(nums) == 1) {
	    		FruitsStorageStockParam stockupdate2 = new FruitsStorageStockParam();
	    		BigDecimal sgweight = new BigDecimal(fruitsStorageStockResult2.getGweight());//库存 毛重
	    		BigDecimal snweight = new BigDecimal(fruitsStorageStockResult2.getWeight());//库存 净重
	    		sgweight = sgweight.subtract(gweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    		snweight = snweight.subtract(nweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    		csnums = csnums.subtract(nums).setScale(2, BigDecimal.ROUND_HALF_DOWN);
	    		stockupdate2.setId(fruitsStorageStockResult2.getId());
	    		stockupdate2.setGweight(sgweight+"");
	    		stockupdate2.setWeight(snweight+"");
	    		stockupdate2.setNums(csnums+"");
	    		fruitsStorageStockService.update(stockupdate2);
    		} else if (csnums.compareTo(nums) == 0) {
	    		FruitsStorageStockParam stockupdate2 = new FruitsStorageStockParam();
	    		stockupdate2.setId(fruitsStorageStockResult2.getId());
	    		stockupdate2.setGweight("0");
	    		stockupdate2.setWeight("0");
	    		stockupdate2.setNums("0");
	    		fruitsStorageStockService.update(stockupdate2);
    		} else {
                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
        		return ResponseData.error("成品仓库存发生变动！");
    		}
    	} else {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
    		return ResponseData.error("成品仓库存发生变动！");
    	}
    	
		return ResponseData.success();
    }

    /**
     * 成品包装  新增
     */
    @ResponseBody
    @RequestMapping("/addItemFruitsPacking")
	@Transactional(rollbackFor = Exception.class,timeout=50)
    public ResponseData addItemFruitsPacking(FruitsPackingParam fruitsPackingParam) {
    	User user = userAop.getUser();

		lock.lock();//获取锁
		try {
	    	FruitsBasicGoodsParam fruitsBasicGoodsParam = new FruitsBasicGoodsParam();
	    	fruitsBasicGoodsParam.setDeptId(user.getDeptId());
	    	fruitsBasicGoodsParam.setGoodsName(fruitsPackingParam.getGoodsName());
	    	FruitsBasicGoodsResult basicGoodsResult = fruitsBasicGoodsService.findBySpec(fruitsBasicGoodsParam,user.getOperateId());
	    	
	    	FruitsStorageStockParam fruitsStorageStockParam = new FruitsStorageStockParam();
	    	fruitsStorageStockParam.setStockstate("在库");
	    	fruitsStorageStockParam.setWarehouseName("加工仓");
	    	fruitsStorageStockParam.setDeptId(user.getDeptId());
	    	fruitsStorageStockParam.setGoodsId(Long.parseLong(basicGoodsResult.getId().toString()));
	    	FruitsStorageStockResult fruitsStorageStockResult = fruitsStorageStockService.findBySpecGt(fruitsStorageStockParam,user.getOperateId());
	    	if(fruitsStorageStockResult == null) {
	            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
	    		return ResponseData.error("库存不足！");
	    	}
	    	
	    	BigDecimal gweight = new BigDecimal(fruitsPackingParam.getGweight());//包装 毛重
	    	BigDecimal nweight = new BigDecimal(fruitsPackingParam.getNweight());//包装 净重
	    	BigDecimal nums = new BigDecimal(fruitsPackingParam.getNums());//包装 净重
	    	BigDecimal weight = new BigDecimal(fruitsStorageStockResult.getWeight());//加工仓 重量
	    	if(weight.compareTo(nweight) == -1) {
	            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
	    		return ResponseData.error("库存不足！");
	    	}
	    	if(weight.compareTo(nweight) == 0) {
	    		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	    		stockupdate.setId(fruitsStorageStockResult.getId());
	    		stockupdate.setWeight("0");
	    		fruitsStorageStockService.update(stockupdate);//更新加工仓 库存重量
	    	}
	    	if(weight.compareTo(nweight) == 1) {
	    		weight = weight.subtract(nweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	    		stockupdate.setId(fruitsStorageStockResult.getId());
	    		stockupdate.setWeight(weight.toString());
	    		fruitsStorageStockService.update(stockupdate);//更新加工仓 库存重量
	    	}

	    	FruitsStorageStockParam fruitsStorageStockParam2 = new FruitsStorageStockParam();
	    	fruitsStorageStockParam2.setStockstate("在库");
	    	fruitsStorageStockParam2.setWarehouseName("成品仓");
	    	fruitsStorageStockParam2.setPositionNumber(fruitsPackingParam.getPositionNumber());
	    	fruitsStorageStockParam2.setGoodsId(Long.parseLong(basicGoodsResult.getId().toString()));
	    	fruitsStorageStockParam2.setGrades(fruitsPackingParam.getGrades());
	    	fruitsStorageStockParam2.setCaseWeightOne(fruitsPackingParam.getCaseWeightOne());
	    	fruitsStorageStockParam2.setProducetime(fruitsStorageStockResult.getProducetime());
	    	fruitsStorageStockParam2.setDeptId(user.getDeptId());
	    	FruitsStorageStockResult fruitsStorageStockResult2 = fruitsStorageStockService.findBySpecByPositionNumber(fruitsStorageStockParam2,user.getOperateId());
	    	if(fruitsStorageStockResult2 == null) {
	    		fruitsStorageStockParam2.setGoodsName(fruitsPackingParam.getGoodsName());
	    		fruitsStorageStockParam2.setCaseWeightOne(fruitsPackingParam.getCaseWeightOne());
	    		fruitsStorageStockParam2.setCaseWeight(fruitsPackingParam.getCaseWeight());
	    		fruitsStorageStockParam2.setGweight(gweight+"");
	    		fruitsStorageStockParam2.setWeight(nweight+"");
	    		fruitsStorageStockParam2.setNums(fruitsPackingParam.getNums());
	    		fruitsStorageStockParam2.setProducetime(fruitsStorageStockResult.getProducetime());
	    		fruitsStorageStockService.add(fruitsStorageStockParam2);
	    	} else {
	    		FruitsStorageStockParam stockupdate2 = new FruitsStorageStockParam();
	    		BigDecimal sgweight = new BigDecimal(fruitsStorageStockResult2.getGweight());
	    		BigDecimal snweight = new BigDecimal(fruitsStorageStockResult2.getWeight());
	    		BigDecimal snums = new BigDecimal(fruitsStorageStockResult2.getNums());
	    		sgweight = sgweight.add(gweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    		snweight = snweight.add(nweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    		snums = snums.add(nums).setScale(2, BigDecimal.ROUND_HALF_DOWN);
	    		stockupdate2.setId(fruitsStorageStockResult2.getId());
	    		stockupdate2.setGweight(sgweight+"");
	    		stockupdate2.setWeight(snweight+"");
	    		stockupdate2.setNums(snums+"");
	    		fruitsStorageStockService.update(stockupdate2);
	    	}
	    	
	    	//新增 成品包装
	    	fruitsPackingParam.setStates("RECEIVED");
	    	fruitsPackingParam.setGoodsId(Long.parseLong(basicGoodsResult.getId().toString()));
	    	fruitsPackingParam.setProducetime(fruitsStorageStockResult.getProducetime());
	    	fruitsPackingParam.setDeptId(user.getDeptId());
	    	fruitsPackingService.add(fruitsPackingParam);
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			lock.unlock();//释放锁
		}
    	return ResponseData.success();
    }
    
    /**
     *查询成品仓、加工仓
     *仓库库存
     */
    @RequestMapping("/findStorageStockSumBySpec3")
    @ResponseBody
    public ResponseData findStorageStockSumBySpec3(FruitsStorageStockParam fruitsStorageStockParam) {
    	User user = userAop.getUser();
    	fruitsStorageStockParam.setDeptId(user.getDeptId());
    	fruitsStorageStockParam.setStockstate("在库");
    	List<FruitsStorageStockResult> list = fruitsStorageStockService.findStorageStockSumBySpec3(fruitsStorageStockParam,user.getOperateId());
        return ResponseData.success(list);
    }
    
    /**
     *查询加工仓、直发仓、次果仓、废果仓
     *仓库库存
     */
    @RequestMapping("/findStorageStockSumBySpec4")
    @ResponseBody
    public ResponseData findStorageStockSumBySpec4(FruitsStorageStockParam fruitsStorageStockParam) {
    	User user = userAop.getUser();
    	fruitsStorageStockParam.setDeptId(user.getDeptId());
    	fruitsStorageStockParam.setStockstate("在库");
    	List<FruitsStorageStockResult> list = fruitsStorageStockService.findStorageStockSumBySpec4(fruitsStorageStockParam,user.getOperateId());
        return ResponseData.success(list);
    }

    /**
     * 查询加工仓 包装列表
     */
    @ResponseBody
    @RequestMapping("/findPackingPagelist")
    public LayuiPageInfo findPackingPagelist(FruitsPackingParam fruitsPackingParam) {
    	User user = userAop.getUser();
    	fruitsPackingParam.setDeptId(user.getDeptId());
        return this.fruitsPackingService.findPackingPagelist(fruitsPackingParam,user.getOperateId());
    }

    @Autowired
    private FruitsBasicChannelService fruitsBasicChannelService;
    
    /**
     *查询渠道
     */
    @RequestMapping("/findChannelBySpec")
    @ResponseBody
    public ResponseData findChannelBySpec(FruitsBasicChannelParam fruitsBasicChannelParam) {
    	User user = userAop.getUser();
    	fruitsBasicChannelParam.setDeptId(user.getDeptId());
    	List<FruitsBasicChannelResult> list = fruitsBasicChannelService.findListBySpec(fruitsBasicChannelParam,user.getOperateId());
        return ResponseData.success(list);
    }
    
    /**
     *查询出库明细
     */
    @RequestMapping("/findOutDetailedBySpec")
    @ResponseBody
    public ResponseData findOutDetailedBySpec(FruitsOrderOutDetailedParam fruitsOrderOutDetailedParam) {
    	List<FruitsOrderOutDetailedResult> list = fruitsOrderOutDetailedService.findListBySpec(fruitsOrderOutDetailedParam);
        return ResponseData.success(list);
    }

    /**
     * 删除接口
     */
    @RequestMapping("/deleteOutDetailed")
    @ResponseBody
    public ResponseData deleteOutDetailed(FruitsOrderOutDetailedParam fruitsOrderOutDetailedParam) {
        this.fruitsOrderOutDetailedService.delete(fruitsOrderOutDetailedParam);
        return ResponseData.success();
    }
    
    /**
     * 成品发货
     *新增出库明细
     */
    @RequestMapping("/addOutDetailed")
    @ResponseBody
    public ResponseData addOutDetailed(FruitsOrderOutDetailedParam fruitsOrderOutDetailedParam) {
    	User user = userAop.getUser();
    	FruitsBasicGoodsParam fruitsBasicGoodsParam = new FruitsBasicGoodsParam();
    	fruitsBasicGoodsParam.setDeptId(user.getDeptId());
    	fruitsBasicGoodsParam.setGoodsName(fruitsOrderOutDetailedParam.getGoodsName());
    	FruitsBasicGoodsResult basicGoodsResult = fruitsBasicGoodsService.findBySpec(fruitsBasicGoodsParam,user.getOperateId());
    	
    	fruitsOrderOutDetailedParam.setStates("已出");
    	fruitsOrderOutDetailedParam.setTimes(DateUtil.getDateS());
    	fruitsOrderOutDetailedParam.setWarehouseName("成品仓");
    	fruitsOrderOutDetailedParam.setGoodsId(Long.parseLong(basicGoodsResult.getId().toString()));
    	fruitsOrderOutDetailedParam.setDeptId(user.getDeptId());
    	fruitsOrderOutDetailedService.add(fruitsOrderOutDetailedParam);
        return ResponseData.success();
    }

    @Autowired
    private FruitsOrderOutService fruitsOrderOutService;

    @Autowired
    private FruitsOrderOutDetailedService fruitsOrderOutDetailedService;

    /**
     *撤销 直发出库
     */
    @RequestMapping("/revoke_zf_out")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class,timeout=50)
    public ResponseData revoke_zf_out(FruitsOrderOutParam fruitsOrderOutParam) {
    	User user = userAop.getUser();
    	FruitsOrderOut fruitsOrderOut = fruitsOrderOutService.getById(fruitsOrderOutParam.getId());
    	if(!fruitsOrderOut.getStates().equals("已出")) {
    		return ResponseData.error("出库单状态已改变！");
    	}
    	fruitsOrderOutParam.setStates("已撤销");
    	fruitsOrderOutService.update(fruitsOrderOutParam);
    	
    	FruitsOrderOutDetailedParam fruitsOrderOutDetailedParam = new FruitsOrderOutDetailedParam();
    	fruitsOrderOutDetailedParam.setOutNumber(fruitsOrderOut.getOutNumber());
    	List<FruitsOrderOutDetailedResult> list = fruitsOrderOutDetailedService.findListBySpec(fruitsOrderOutDetailedParam);
    	for (FruitsOrderOutDetailedResult r : list) {
	    	FruitsStorageStockParam fruitsStorageStockParam = new FruitsStorageStockParam();
	    	fruitsStorageStockParam.setStockstate("在库");
	    	fruitsStorageStockParam.setWarehouseName(r.getWarehouseName());
	    	fruitsStorageStockParam.setGoodsId(r.getGoodsId());
	    	fruitsStorageStockParam.setProducetime(r.getProducetime());
	    	fruitsStorageStockParam.setDeptId(user.getDeptId());
	    	FruitsStorageStockResult fruitsStorageStockResult = fruitsStorageStockService.findBySpec(fruitsStorageStockParam,user.getOperateId());
    		if(fruitsStorageStockResult == null) {
    			fruitsStorageStockParam.setGoodsName(r.getGoodsName());
    			fruitsStorageStockParam.setWeight(r.getWeight());
    			fruitsStorageStockService.add(fruitsStorageStockParam);
    		} else {
    			BigDecimal weight = new BigDecimal(r.getWeight());
    			BigDecimal sweight = new BigDecimal(fruitsStorageStockResult.getWeight());
    			sweight = sweight.add(weight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
    			FruitsStorageStockParam updateStockParam = new  FruitsStorageStockParam();
    			updateStockParam.setId(fruitsStorageStockResult.getId());
    			updateStockParam.setWeight(sweight.toString());
    			fruitsStorageStockService.update(updateStockParam);
    		}
    		FruitsOrderOutDetailedParam updateOutDetailedParam = new FruitsOrderOutDetailedParam();
    		updateOutDetailedParam.setId(r.getId());
    		updateOutDetailedParam.setStates("已撤销");
    		fruitsOrderOutDetailedService.update(updateOutDetailedParam);
		}
		return ResponseData.success();
    }
    
    /**
     *直发出库
     */
    @RequestMapping("/addItemOut")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class,timeout=50)
    public ResponseData addItemOut(FruitsOrderOutParam fruitsOrderOutParam,FruitsOrderOutDetailedParam fruitsOrderOutDetailedParam) {
    	User user = userAop.getUser();

		lock.lock();//获取锁
		try {
	    	FruitsOrderOutParam to = new FruitsOrderOutParam();
	    	to.setTimes(DateUtil.getDate());
	    	to.setDeptId(user.getDeptId());
	    	int count = fruitsOrderOutService.countBydate(to,user.getOperateId());
	    	
	    	//添加出库单
	    	fruitsOrderOutParam.setStates("已出");
	    	fruitsOrderOutParam.setOutNumber("CZF"+DateUtil.getDateBch()+(count+1));
	    	fruitsOrderOutParam.setWarehouseName("直发仓");
	    	
	    	if(ToolUtil.isNotEmpty(fruitsOrderOutParam.getCustomerName())) {
	    		FruitsBasicCustomerParam basicCustomerParam = new FruitsBasicCustomerParam();
	    		basicCustomerParam.setCustomerName(fruitsOrderOutParam.getCustomerName());
	    		basicCustomerParam.setDeptId(user.getDeptId());
	    		FruitsBasicCustomerResult basicCustomerResult = fruitsBasicCustomerService.findBySpec(basicCustomerParam,user.getOperateId());
	    		if(basicCustomerResult != null) {
	    	    	fruitsOrderOutParam.setChannelName(basicCustomerResult.getChannelName());
	    	    	fruitsOrderOutParam.setCustomerAddress(basicCustomerResult.getCustomerAddress());
	    	    	fruitsOrderOutParam.setContacts(basicCustomerResult.getContacts());
	    	    	fruitsOrderOutParam.setTel(basicCustomerResult.getTel());
	    	    	fruitsOrderOutParam.setSettlementMethod(basicCustomerResult.getSettlementMethod());
	    	    	fruitsOrderOutParam.setChannelPlatform(basicCustomerResult.getChannelPlatform());
	    	    	fruitsOrderOutParam.setTransportModel(basicCustomerResult.getTransportModel());
	    		}
	    	}
	    	fruitsOrderOutParam.setDeptId(user.getDeptId());
	    	fruitsOrderOutService.add(fruitsOrderOutParam);
	    	
	    	//查询商品
	    	FruitsBasicGoodsParam fruitsBasicGoodsParam = new FruitsBasicGoodsParam();
	    	fruitsBasicGoodsParam.setDeptId(user.getDeptId());
	    	fruitsBasicGoodsParam.setGoodsName(fruitsOrderOutDetailedParam.getGoodsName());
	    	FruitsBasicGoodsResult basicGoodsResult = fruitsBasicGoodsService.findBySpec(fruitsBasicGoodsParam,user.getOperateId());
	    	
	    	//新增出库明细  扣减库存
	    	fruitsOrderOutDetailedParam.setStates("已出");
	    	fruitsOrderOutDetailedParam.setTimes(DateUtil.getDateS());
	    	fruitsOrderOutDetailedParam.setOutNumber(fruitsOrderOutParam.getOutNumber());
	    	fruitsOrderOutDetailedParam.setWarehouseName("直发仓");
	    	fruitsOrderOutDetailedParam.setGoodsId(Long.parseLong(basicGoodsResult.getId().toString()));
	    	fruitsOrderOutDetailedParam.setDeptId(user.getDeptId());

	    	BigDecimal as = new BigDecimal(0);
	    	BigDecimal weight = new BigDecimal(fruitsOrderOutDetailedParam.getWeight());//出库重量
	    	
	    	FruitsStorageStockParam fruitsStorageStockParam = new FruitsStorageStockParam();
	    	fruitsStorageStockParam.setStockstate("在库");
	    	fruitsStorageStockParam.setWarehouseName("直发仓");
	    	fruitsStorageStockParam.setDeptId(user.getDeptId());
	    	fruitsStorageStockParam.setGoodsId(fruitsOrderOutDetailedParam.getGoodsId());
	    	List<FruitsStorageStockResult> list = fruitsStorageStockService.findListBySpec(fruitsStorageStockParam,user.getOperateId());
	    	if(list.size() == 0) {
	            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
	    		return ResponseData.error("库存不足！");
	    	}
	    	for (int i = 0; i < list.size(); i++) {
	    		FruitsStorageStockResult r = list.get(i);
	        	BigDecimal sweight = new BigDecimal(r.getWeight());//库存重量
	        	if(sweight.compareTo(weight) == 1) {//如果库存大于出库重量
	        		sweight = sweight.subtract(weight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	        		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	        		stockupdate.setId(r.getId());
	        		stockupdate.setWeight(sweight.toString());
	        		fruitsStorageStockService.update(stockupdate);//更新库存重量
	        		
	        		fruitsOrderOutDetailedParam.setProducetime(r.getProducetime());
	        		fruitsOrderOutDetailedParam.setPositionNumber(r.getPositionNumber());
	        		fruitsOrderOutDetailedParam.setWeight(weight.toString());
	        		fruitsOrderOutDetailedService.add(fruitsOrderOutDetailedParam);//添加出库明细
	        		
	        		weight = as;
	        		break;
	        	} else if (sweight.compareTo(weight) == 0) {//如果库存等于出库重量
	        		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	        		stockupdate.setId(r.getId());
	        		stockupdate.setWeight("0");
	        		fruitsStorageStockService.update(stockupdate);//更新库存重量

	        		fruitsOrderOutDetailedParam.setProducetime(r.getProducetime());
	        		fruitsOrderOutDetailedParam.setPositionNumber(r.getPositionNumber());
	        		fruitsOrderOutDetailedParam.setWeight(weight.toString());
	        		fruitsOrderOutDetailedService.add(fruitsOrderOutDetailedParam);//添加出库明细
	        		weight = as;
	        		break;
	        	} else {//如果库存小于出库重量
	        		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	        		stockupdate.setId(r.getId());
	        		stockupdate.setWeight("0");
	        		fruitsStorageStockService.update(stockupdate);//更新库存重量

	        		fruitsOrderOutDetailedParam.setProducetime(r.getProducetime());
	        		fruitsOrderOutDetailedParam.setPositionNumber(r.getPositionNumber());
	        		weight = weight.subtract(sweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	        		fruitsOrderOutDetailedParam.setWeight(sweight.toString());
	        		fruitsOrderOutDetailedService.add(fruitsOrderOutDetailedParam);//添加出库明细
	        	}
			}
	    	if(weight.compareTo(as) == 1) {
	            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
	    		return ResponseData.error("库存不足！");
	    	}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			lock.unlock();//释放锁
		}
    	
        return ResponseData.success();
    }

    /**
     *撤销 次果处置
     */
    @RequestMapping("/revoke_cz_out")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class,timeout=50)
    public ResponseData revoke_cz_out(FruitsOrderOutParam fruitsOrderOutParam) {
    	User user = userAop.getUser();
    	FruitsOrderOut fruitsOrderOut = fruitsOrderOutService.getById(fruitsOrderOutParam.getId());
    	if(!fruitsOrderOut.getStates().equals("已出")) {
    		return ResponseData.error("处置单状态已变！");
    	}
    	fruitsOrderOutParam.setStates("已撤销");
    	fruitsOrderOutService.update(fruitsOrderOutParam);
    	
    	FruitsOrderOutDetailedParam fruitsOrderOutDetailedParam = new FruitsOrderOutDetailedParam();
    	fruitsOrderOutDetailedParam.setOutNumber(fruitsOrderOut.getOutNumber());
    	List<FruitsOrderOutDetailedResult> list = fruitsOrderOutDetailedService.findListBySpec(fruitsOrderOutDetailedParam);
    	for (FruitsOrderOutDetailedResult r : list) {
	    	FruitsStorageStockParam fruitsStorageStockParam = new FruitsStorageStockParam();
	    	fruitsStorageStockParam.setStockstate("在库");
	    	fruitsStorageStockParam.setWarehouseName(r.getWarehouseName());
	    	fruitsStorageStockParam.setGoodsId(r.getGoodsId());
	    	fruitsStorageStockParam.setProducetime(r.getProducetime());
	    	fruitsStorageStockParam.setDeptId(user.getDeptId());
	    	FruitsStorageStockResult fruitsStorageStockResult = fruitsStorageStockService.findBySpec(fruitsStorageStockParam,user.getOperateId());
    		if(fruitsStorageStockResult == null) {
    			fruitsStorageStockParam.setGoodsName(r.getGoodsName());
    			fruitsStorageStockParam.setWeight(r.getWeight());
    			fruitsStorageStockService.add(fruitsStorageStockParam);
    		} else {
    			BigDecimal weight = new BigDecimal(r.getWeight());
    			BigDecimal sweight = new BigDecimal(fruitsStorageStockResult.getWeight());
    			sweight = sweight.add(weight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
    			FruitsStorageStockParam updateStockParam = new  FruitsStorageStockParam();
    			updateStockParam.setId(fruitsStorageStockResult.getId());
    			updateStockParam.setWeight(sweight.toString());
    			fruitsStorageStockService.update(updateStockParam);
    		}
    		FruitsOrderOutDetailedParam updateOutDetailedParam = new FruitsOrderOutDetailedParam();
    		updateOutDetailedParam.setId(r.getId());
    		updateOutDetailedParam.setStates("已撤销");
    		fruitsOrderOutDetailedService.update(updateOutDetailedParam);
		}
		return ResponseData.success();
    }
    
    /**
     *次果处置
     */
    @RequestMapping("/addItemOutDefectiveproduct")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class,timeout=50)
    public ResponseData addItemOutDefectiveproduct(FruitsOrderOutParam fruitsOrderOutParam,FruitsOrderOutDetailedParam fruitsOrderOutDetailedParam) {
    	User user = userAop.getUser();

		lock.lock();//获取锁
		try {
	    	FruitsOrderOutParam to = new FruitsOrderOutParam();
	    	to.setTimes(DateUtil.getDate());
	    	to.setDeptId(user.getDeptId());
	    	int count = fruitsOrderOutService.countBydate(to,user.getOperateId());
	    	
	    	//添加出库单
	    	fruitsOrderOutParam.setStates("已出");
	    	fruitsOrderOutParam.setOutNumber("CCZ"+DateUtil.getDateBch()+(count+1));
	    	fruitsOrderOutParam.setWarehouseName("次果仓");
	    	
	    	if(ToolUtil.isNotEmpty(fruitsOrderOutParam.getCustomerName())) {
	    		FruitsBasicCustomerParam basicCustomerParam = new FruitsBasicCustomerParam();
	    		basicCustomerParam.setCustomerName(fruitsOrderOutParam.getCustomerName());
	    		basicCustomerParam.setDeptId(user.getDeptId());
	    		FruitsBasicCustomerResult basicCustomerResult = fruitsBasicCustomerService.findBySpec(basicCustomerParam,user.getOperateId());
	    		if(basicCustomerResult != null) {
	    	    	fruitsOrderOutParam.setChannelName(basicCustomerResult.getChannelName());
	    	    	fruitsOrderOutParam.setCustomerAddress(basicCustomerResult.getCustomerAddress());
	    	    	fruitsOrderOutParam.setContacts(basicCustomerResult.getContacts());
	    	    	fruitsOrderOutParam.setTel(basicCustomerResult.getTel());
	    	    	fruitsOrderOutParam.setSettlementMethod(basicCustomerResult.getSettlementMethod());
	    	    	fruitsOrderOutParam.setChannelPlatform(basicCustomerResult.getChannelPlatform());
	    	    	fruitsOrderOutParam.setTransportModel(basicCustomerResult.getTransportModel());
	    		}
	    	}
	    	fruitsOrderOutParam.setDeptId(user.getDeptId());
	    	fruitsOrderOutService.add(fruitsOrderOutParam);
	    	
	    	//查询商品
	    	FruitsBasicGoodsParam fruitsBasicGoodsParam = new FruitsBasicGoodsParam();
	    	fruitsBasicGoodsParam.setDeptId(user.getDeptId());
	    	fruitsBasicGoodsParam.setGoodsName(fruitsOrderOutDetailedParam.getGoodsName());
	    	FruitsBasicGoodsResult basicGoodsResult = fruitsBasicGoodsService.findBySpec(fruitsBasicGoodsParam,user.getOperateId());
	    	
	    	//新增出库明细  扣减库存
	    	fruitsOrderOutDetailedParam.setStates("已出");
	    	fruitsOrderOutDetailedParam.setTimes(DateUtil.getDateS());
	    	fruitsOrderOutDetailedParam.setOutNumber(fruitsOrderOutParam.getOutNumber());
	    	fruitsOrderOutDetailedParam.setWarehouseName("次果仓");
	    	fruitsOrderOutDetailedParam.setGoodsId(Long.parseLong(basicGoodsResult.getId().toString()));
	    	fruitsOrderOutDetailedParam.setDeptId(user.getDeptId());

	    	BigDecimal as = new BigDecimal(0);
	    	BigDecimal weight = new BigDecimal(fruitsOrderOutDetailedParam.getWeight());//出库重量
	    	
	    	FruitsStorageStockParam fruitsStorageStockParam = new FruitsStorageStockParam();
	    	fruitsStorageStockParam.setStockstate("在库");
	    	fruitsStorageStockParam.setWarehouseName("次果仓");
	    	fruitsStorageStockParam.setDeptId(user.getDeptId());
	    	fruitsStorageStockParam.setGoodsId(fruitsOrderOutDetailedParam.getGoodsId());
	    	List<FruitsStorageStockResult> list = fruitsStorageStockService.findListBySpec(fruitsStorageStockParam,user.getOperateId());
	    	if(list.size() == 0) {
	            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
	    		return ResponseData.error("库存不足！");
	    	}
	    	for (int i = 0; i < list.size(); i++) {
	    		FruitsStorageStockResult r = list.get(i);
	        	BigDecimal sweight = new BigDecimal(r.getWeight());//库存重量
	        	if(sweight.compareTo(weight) == 1) {//如果库存大于出库重量
	        		sweight = sweight.subtract(weight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	        		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	        		stockupdate.setId(r.getId());
	        		stockupdate.setWeight(sweight.toString());
	        		fruitsStorageStockService.update(stockupdate);//更新库存重量
	        		
	        		fruitsOrderOutDetailedParam.setProducetime(r.getProducetime());
	        		fruitsOrderOutDetailedParam.setPositionNumber(r.getPositionNumber());
	        		fruitsOrderOutDetailedParam.setWeight(weight.toString());
	        		fruitsOrderOutDetailedService.add(fruitsOrderOutDetailedParam);//添加出库明细
	        		
	        		weight = as;
	        		break;
	        	} else if (sweight.compareTo(weight) == 0) {//如果库存等于出库重量
	        		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	        		stockupdate.setId(r.getId());
	        		stockupdate.setWeight("0");
	        		fruitsStorageStockService.update(stockupdate);//更新库存重量

	        		fruitsOrderOutDetailedParam.setProducetime(r.getProducetime());
	        		fruitsOrderOutDetailedParam.setPositionNumber(r.getPositionNumber());
	        		fruitsOrderOutDetailedParam.setWeight(weight.toString());
	        		fruitsOrderOutDetailedService.add(fruitsOrderOutDetailedParam);//添加出库明细
	        		weight = as;
	        		break;
	        	} else {//如果库存小于出库重量
	        		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	        		stockupdate.setId(r.getId());
	        		stockupdate.setWeight("0");
	        		fruitsStorageStockService.update(stockupdate);//更新库存重量

	        		fruitsOrderOutDetailedParam.setProducetime(r.getProducetime());
	        		fruitsOrderOutDetailedParam.setPositionNumber(r.getPositionNumber());
	        		weight = weight.subtract(sweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	        		fruitsOrderOutDetailedParam.setWeight(sweight.toString());
	        		fruitsOrderOutDetailedService.add(fruitsOrderOutDetailedParam);//添加出库明细
	        	}
			}
	    	if(weight.compareTo(as) == 1) {
	            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
	    		return ResponseData.error("库存不足！");
	    	}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			lock.unlock();//释放锁
		}
        return ResponseData.success();
    }
    
    /**
     * 撤销 成品发货
     */
    @RequestMapping("/revoke_cp_out")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class,timeout=50)
    public ResponseData revoke_cp_out(FruitsOrderOutParam fruitsOrderOutParam) {
    	User user = userAop.getUser();
    	FruitsOrderOut fruitsOrderOut = fruitsOrderOutService.getById(fruitsOrderOutParam.getId());
    	if(!fruitsOrderOut.getStates().equals("已出")) {
    		return ResponseData.error("出库单状态已改变！");
    	}
    	fruitsOrderOutParam.setStates("已撤销");
    	fruitsOrderOutService.update(fruitsOrderOutParam);

    	FruitsOrderOutDetailedParam detailedParam = new FruitsOrderOutDetailedParam();
    	detailedParam.setOutNumber(fruitsOrderOut.getOutNumber());
    	List<FruitsOrderOutDetailedResult> list =  fruitsOrderOutDetailedService.findListBySpec(detailedParam);
    	for (FruitsOrderOutDetailedResult r : list) {
        	FruitsStorageStockParam fruitsStorageStockParam = new FruitsStorageStockParam();
        	fruitsStorageStockParam.setStockstate("在库");
        	fruitsStorageStockParam.setWarehouseName("成品仓");
        	fruitsStorageStockParam.setPositionNumber(r.getPositionNumber());
        	fruitsStorageStockParam.setGoodsId(r.getGoodsId());
        	fruitsStorageStockParam.setGrades(r.getGrades());
        	fruitsStorageStockParam.setCaseWeightOne(r.getCaseWeightOne());
        	fruitsStorageStockParam.setDeptId(user.getDeptId());
        	FruitsStorageStockResult fruitsStorageStockResult = fruitsStorageStockService.findBySpecByPositionNumber(fruitsStorageStockParam,user.getOperateId());
    		if(fruitsStorageStockResult == null) {
    			fruitsStorageStockParam.setGoodsName(r.getGoodsName());
    			fruitsStorageStockParam.setWeight(r.getWeight());
    			fruitsStorageStockParam.setGweight(r.getGweight());
    			fruitsStorageStockParam.setNums(r.getNums());
    			fruitsStorageStockService.add(fruitsStorageStockParam);
    		} else {
    			BigDecimal gweight = new BigDecimal(r.getGweight());//出库毛重
    			BigDecimal weight = new BigDecimal(r.getWeight());//出库净重
    			BigDecimal nums = new BigDecimal(r.getNums());//出库箱数

    			BigDecimal sgweight = new BigDecimal(fruitsStorageStockResult.getGweight());//库存毛重
    			BigDecimal sweight = new BigDecimal(fruitsStorageStockResult.getWeight());//库存净重
    			BigDecimal snums = new BigDecimal(fruitsStorageStockResult.getNums());//库存箱数
    			sgweight = sgweight.add(gweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
    			sweight = sweight.add(weight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
    			snums = snums.add(nums).setScale(2, BigDecimal.ROUND_HALF_DOWN);

        		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
        		stockupdate.setId(fruitsStorageStockResult.getId());
        		stockupdate.setGweight(sgweight.toString());
        		stockupdate.setWeight(sweight.toString());
        		stockupdate.setNums(snums.toString());
        		fruitsStorageStockService.update(stockupdate);
    		}
    		detailedParam.setId(r.getId());
    		detailedParam.setStates("已撤销");
    		fruitsOrderOutDetailedService.update(detailedParam);
		}
		return ResponseData.success();
    }
    
    /**
     * 成品发货
     */
    @RequestMapping("/addPackingOrder")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class,timeout=50)
    public ResponseData addPackingOrder(FruitsOrderOutParam fruitsOrderOutParam) {
    	User user = userAop.getUser();
    	FruitsOrderOutDetailedParam detailedParam = new FruitsOrderOutDetailedParam();
    	detailedParam.setOutNumber(fruitsOrderOutParam.getOutNumber());
    	List<FruitsOrderOutDetailedResult> list =  fruitsOrderOutDetailedService.findListBySpec(detailedParam);
    	if(list.size()==0) {
    		return ResponseData.error("请先添加出库明细！");
    	}

		lock.lock();//获取锁
		try {
	    	//添加出库单
	    	fruitsOrderOutParam.setStates("已出");
	    	fruitsOrderOutParam.setWarehouseName("成品仓");
	    	if(ToolUtil.isNotEmpty(fruitsOrderOutParam.getCustomerName())) {
	    		FruitsBasicCustomerParam basicCustomerParam = new FruitsBasicCustomerParam();
	    		basicCustomerParam.setCustomerName(fruitsOrderOutParam.getCustomerName());
	    		basicCustomerParam.setDeptId(user.getDeptId());
	    		FruitsBasicCustomerResult basicCustomerResult = fruitsBasicCustomerService.findBySpec(basicCustomerParam,user.getOperateId());
	    		if(basicCustomerResult != null) {
	    	    	fruitsOrderOutParam.setCustomerAddress(basicCustomerResult.getCustomerAddress());
	    	    	fruitsOrderOutParam.setContacts(basicCustomerResult.getContacts());
	    	    	fruitsOrderOutParam.setTel(basicCustomerResult.getTel());
	    	    	fruitsOrderOutParam.setSettlementMethod(basicCustomerResult.getSettlementMethod());
	    	    	fruitsOrderOutParam.setChannelPlatform(basicCustomerResult.getChannelPlatform());
	    	    	fruitsOrderOutParam.setTransportModel(basicCustomerResult.getTransportModel());
	    		}
	    	}
	    	fruitsOrderOutParam.setDeptId(user.getDeptId());
	    	fruitsOrderOutService.add(fruitsOrderOutParam);
	    	
	    	//扣减库存  更新出库明细
	    	for (FruitsOrderOutDetailedResult r : list) {
	        	FruitsStorageStockParam fruitsStorageStockParam = new FruitsStorageStockParam();
	        	fruitsStorageStockParam.setStockstate("在库");
	        	fruitsStorageStockParam.setWarehouseName("成品仓");
	        	fruitsStorageStockParam.setGoodsId(r.getGoodsId());
	        	fruitsStorageStockParam.setGrades(r.getGrades());
	        	fruitsStorageStockParam.setCaseWeightOne(r.getCaseWeightOne());
	        	fruitsStorageStockParam.setDeptId(user.getDeptId());
	        	List<FruitsStorageStockResult> slist = fruitsStorageStockService.findListBySpec(fruitsStorageStockParam,user.getOperateId());
	        	if(slist.size() == 0) {
	                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
	        		return ResponseData.error("库存不足！");
	        	}
	        	
	        	BigDecimal gweight = new BigDecimal(r.getGweight());//出库毛重
	        	BigDecimal weight = new BigDecimal(r.getWeight());//出库净重
	        	BigDecimal nums = new BigDecimal(r.getNums());//出库箱数
	    		for (FruitsStorageStockResult r2 : slist) {
	            	BigDecimal sgweight = new BigDecimal(r2.getGweight());//出库毛重
	            	BigDecimal sweight = new BigDecimal(r2.getWeight());//出库净重
	            	BigDecimal snums = new BigDecimal(r2.getNums());//库存箱数
	    			if(snums.compareTo(nums) == 1) {//库存大于  出库数
	    				sgweight = sgweight.subtract(gweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	            		sweight = sweight.subtract(weight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    				snums = snums.subtract(nums).setScale(2, BigDecimal.ROUND_HALF_DOWN);
	            		
	            		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	            		stockupdate.setId(r2.getId());
	            		stockupdate.setGweight(sgweight.toString());
	            		stockupdate.setWeight(sweight.toString());
	            		stockupdate.setNums(snums.toString());
	            		fruitsStorageStockService.update(stockupdate);//更新库存重量

	                	FruitsOrderOutDetailedParam updatedetailedParam = new FruitsOrderOutDetailedParam();
	                	updatedetailedParam.setId(r.getId());
	                	updatedetailedParam.setPositionNumber(r2.getPositionNumber());
	                	updatedetailedParam.setGweight(gweight.toString());
	                	updatedetailedParam.setWeight(weight.toString());
	                	updatedetailedParam.setNums(nums.toString());
	                	updatedetailedParam.setProducetime(r2.getProducetime());
	            		fruitsOrderOutDetailedService.update(updatedetailedParam);//更新出库明细
	            		
	    				gweight = new BigDecimal(0);
	    				weight = new BigDecimal(0);
	    				nums = new BigDecimal(0);
	            		break;
	    			} else if (snums.compareTo(nums) == 0) {//库存等于  出库数
	            		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	            		stockupdate.setId(r2.getId());
	            		stockupdate.setGweight("0");
	            		stockupdate.setWeight("0");
	            		stockupdate.setNums("0");
	            		fruitsStorageStockService.update(stockupdate);//更新库存重量

	                	FruitsOrderOutDetailedParam updatedetailedParam = new FruitsOrderOutDetailedParam();
	                	updatedetailedParam.setPositionNumber(r2.getPositionNumber());
	                	updatedetailedParam.setId(r.getId());
	                	updatedetailedParam.setProducetime(r2.getProducetime());
	            		fruitsOrderOutDetailedService.update(updatedetailedParam);//更新出库明细
	            		
	    				gweight = new BigDecimal(0);
	    				weight = new BigDecimal(0);
	    				nums = new BigDecimal(0);
	            		break;
	    			} else {//库存小于  出库数
	    				//减除出库数
	    				gweight = gweight.subtract(sgweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    				weight = weight.subtract(sweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    				nums = nums.subtract(snums).setScale(2, BigDecimal.ROUND_HALF_DOWN);

	            		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	            		stockupdate.setId(r2.getId());
	            		stockupdate.setGweight("0");
	            		stockupdate.setWeight("0");
	            		stockupdate.setNums("0");
	            		fruitsStorageStockService.update(stockupdate);//更新库存重量
	    				
	                	FruitsOrderOutDetailedParam adddetailedParam = new FruitsOrderOutDetailedParam();
	            		ToolUtil.copyProperties(r, adddetailedParam);
	            		adddetailedParam.setId(null);
	            		adddetailedParam.setPositionNumber(r2.getPositionNumber());
	            		adddetailedParam.setGweight(sgweight.toString());
	            		adddetailedParam.setWeight(sweight.toString());
	            		adddetailedParam.setNums(snums.toString());
	            		adddetailedParam.setProducetime(r2.getProducetime());
	            		fruitsOrderOutDetailedService.add(adddetailedParam);
	    			}
				}
	    		BigDecimal as = new BigDecimal(0);
	    		if(nums.compareTo(as) == 1) {
	                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
	        		return ResponseData.error("库存不足！");
	    		}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			lock.unlock();//释放锁
		}
        return ResponseData.success();
    }

    @Autowired
    private FruitsAllocationService fruitsAllocationService;
    
    /**
     * 新增 调拨
     */
    @RequestMapping("/addAllocation")
    @ResponseBody
	@Transactional(rollbackFor = Exception.class,timeout=50)
    public ResponseData addAllocation(FruitsAllocationParam fruitsAllocationParam) {
    	User user = userAop.getUser();
    	
		lock.lock();//获取锁
		try {
	    	FruitsBasicGoodsParam fruitsBasicGoodsParam = new FruitsBasicGoodsParam();
	    	fruitsBasicGoodsParam.setDeptId(user.getDeptId());
	    	fruitsBasicGoodsParam.setGoodsName(fruitsAllocationParam.getGoodsName());
	    	FruitsBasicGoodsResult basicGoodsResult = fruitsBasicGoodsService.findBySpec(fruitsBasicGoodsParam,user.getOperateId());
	    	
	    	fruitsAllocationParam.setStates("已完成");
	    	fruitsAllocationParam.setTimes(DateUtil.getDateS());
	    	fruitsAllocationParam.setGoodsId(Long.parseLong(basicGoodsResult.getId().toString()));
	    	fruitsAllocationParam.setUserName(user.getName());
	    	fruitsAllocationParam.setDeptId(user.getDeptId());
	    	
	    	FruitsStorageStockParam fruitsStorageStockParam = new FruitsStorageStockParam();
	    	fruitsStorageStockParam.setStockstate("在库");
	    	fruitsStorageStockParam.setWarehouseName(fruitsAllocationParam.getWarehouseNameOut());
	    	fruitsStorageStockParam.setGoodsId(fruitsAllocationParam.getGoodsId());
	    	fruitsStorageStockParam.setDeptId(user.getDeptId());
	    	List<FruitsStorageStockResult> slist = fruitsStorageStockService.findListBySpecAndPositionNumber(fruitsStorageStockParam,user.getOperateId());
	    	if(slist.size() == 0) {
	            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
	    		return ResponseData.error("调出仓库库存不足！");
	    	}
	    	
	    	BigDecimal nweight = new BigDecimal(fruitsAllocationParam.getNweight());//调出重量
	    	for (FruitsStorageStockResult r : slist) {
				BigDecimal sweight = new BigDecimal(r.getWeight());//库存重量
				if(sweight.compareTo(nweight) == 1) {//库存大于   调出重量
					//减调出库存
					sweight = sweight.subtract(nweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	        		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	        		stockupdate.setId(r.getId());
	        		stockupdate.setWeight(sweight.toString());
	        		fruitsStorageStockService.update(stockupdate);//更新库存重量
	        		
	        		//加调入库存
	    	    	FruitsStorageStockParam addStorageStockParam = new FruitsStorageStockParam();
	    	    	addStorageStockParam.setStockstate("在库");
	    	    	addStorageStockParam.setProducetime(r.getProducetime());
	    	    	addStorageStockParam.setWarehouseName(fruitsAllocationParam.getWarehouseNamePut());
	    	    	addStorageStockParam.setGoodsId(r.getGoodsId());
	    	    	addStorageStockParam.setDeptId(user.getDeptId());
	    	    	FruitsStorageStockResult fruitsStorageStockResult = fruitsStorageStockService.findBySpec(addStorageStockParam,user.getOperateId());
	    	    	if(fruitsStorageStockResult != null) {
	    	    		BigDecimal sweightadd = new BigDecimal(fruitsStorageStockResult.getWeight());
	    	    		sweightadd = sweightadd.add(nweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    	    		addStorageStockParam.setId(fruitsStorageStockResult.getId());
	    	    		addStorageStockParam.setWeight(sweightadd.toString());
	    	    		fruitsStorageStockService.update(addStorageStockParam);
	    	    	} else {
	    	    		addStorageStockParam.setGoodsName(r.getGoodsName());
	    	    		addStorageStockParam.setWeight(nweight.toString());
	    	    		fruitsStorageStockService.add(addStorageStockParam);
	    	    	}

	    	    	//新增 调拨
	    	    	fruitsAllocationParam.setNweight(nweight.toString());
	    	    	fruitsAllocationParam.setProducetime(r.getProducetime());
	    	    	fruitsAllocationService.add(fruitsAllocationParam);
	    	    	nweight = new BigDecimal(0);
	    	    	break;
				} else if(sweight.compareTo(nweight) == 0) {
					//减调出库存
	        		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	        		stockupdate.setId(r.getId());
	        		stockupdate.setWeight("0");
	        		fruitsStorageStockService.update(stockupdate);//更新库存重量
	        		
	        		//加调入库存
	    	    	FruitsStorageStockParam addStorageStockParam = new FruitsStorageStockParam();
	    	    	addStorageStockParam.setStockstate("在库");
	    	    	addStorageStockParam.setProducetime(r.getProducetime());
	    	    	addStorageStockParam.setWarehouseName(fruitsAllocationParam.getWarehouseNamePut());
	    	    	addStorageStockParam.setGoodsId(r.getGoodsId());
	    	    	addStorageStockParam.setDeptId(user.getDeptId());
	    	    	FruitsStorageStockResult fruitsStorageStockResult = fruitsStorageStockService.findBySpec(addStorageStockParam,user.getOperateId());
	    	    	if(fruitsStorageStockResult != null) {
	    	    		BigDecimal sweightadd = new BigDecimal(fruitsStorageStockResult.getWeight());
	    	    		sweightadd = sweightadd.add(nweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    	    		addStorageStockParam.setId(fruitsStorageStockResult.getId());
	    	    		addStorageStockParam.setWeight(sweightadd.toString());
	    	    		fruitsStorageStockService.update(addStorageStockParam);
	    	    	} else {
	    	    		addStorageStockParam.setGoodsName(r.getGoodsName());
	    	    		addStorageStockParam.setWeight(nweight.toString());
	    	    		fruitsStorageStockService.add(addStorageStockParam);
	    	    	}

	    	    	//新增 调拨
	    	    	fruitsAllocationParam.setNweight(nweight.toString());
	    	    	fruitsAllocationParam.setProducetime(r.getProducetime());
	    	    	fruitsAllocationService.add(fruitsAllocationParam);
	    	    	nweight = new BigDecimal(0);
	    	    	break;
				} else {
					//减调出库存
	        		FruitsStorageStockParam stockupdate = new FruitsStorageStockParam();
	        		stockupdate.setId(r.getId());
	        		stockupdate.setWeight("0");
	        		fruitsStorageStockService.update(stockupdate);//更新库存重量
	        		
	        		//加调入库存
	    	    	FruitsStorageStockParam addStorageStockParam = new FruitsStorageStockParam();
	    	    	addStorageStockParam.setStockstate("在库");
	    	    	addStorageStockParam.setProducetime(r.getProducetime());
	    	    	addStorageStockParam.setWarehouseName(fruitsAllocationParam.getWarehouseNamePut());
	    	    	addStorageStockParam.setGoodsId(r.getGoodsId());
	    	    	addStorageStockParam.setDeptId(user.getDeptId());
	    	    	FruitsStorageStockResult fruitsStorageStockResult = fruitsStorageStockService.findBySpec(addStorageStockParam,user.getOperateId());
	    	    	if(fruitsStorageStockResult != null) {
	    	    		BigDecimal sweightadd = new BigDecimal(fruitsStorageStockResult.getWeight());
	    	    		sweightadd = sweightadd.add(sweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
	    	    		addStorageStockParam.setId(fruitsStorageStockResult.getId());
	    	    		addStorageStockParam.setWeight(sweightadd.toString());
	    	    		fruitsStorageStockService.update(addStorageStockParam);
	    	    	} else {
	    	    		addStorageStockParam.setGoodsName(r.getGoodsName());
	    	    		addStorageStockParam.setWeight(sweight.toString());
	    	    		fruitsStorageStockService.add(addStorageStockParam);
	    	    	}

	    	    	//新增 调拨
	    	    	fruitsAllocationParam.setNweight(sweight.toString());
	    	    	fruitsAllocationParam.setProducetime(r.getProducetime());
	    	    	fruitsAllocationService.add(fruitsAllocationParam);
	    	    	nweight = nweight.subtract(sweight).setScale(3, BigDecimal.ROUND_HALF_DOWN);
				}
			}
			BigDecimal as = new BigDecimal(0);
			if(nweight.compareTo(as) == 1) {
	            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly(); //手动回滚
	    		return ResponseData.error("调出仓库库存不足！");
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			lock.unlock();//释放锁
		}
        return ResponseData.success();
    }

    /**
     * 查询列表
     */
    @ResponseBody
    @RequestMapping("/findAllocationPage")
    public LayuiPageInfo findAllocationPage(FruitsAllocationParam fruitsAllocationParam) {
    	User user = userAop.getUser();
    	fruitsAllocationParam.setDeptId(user.getDeptId());
        return this.fruitsAllocationService.findPageBySpec(fruitsAllocationParam,null,user.getOperateId());
    }
    
    /**
     *查询
     *仓库库存
     */
    @RequestMapping("/findStorageStockListBySpec")
    @ResponseBody
    public ResponseData findStorageStockListBySpec(FruitsStorageStockParam fruitsStorageStockParam) {
    	User user = userAop.getUser();
    	fruitsStorageStockParam.setDeptId(user.getDeptId());
    	fruitsStorageStockParam.setStockstate("在库");
    	List<FruitsStorageStockResult> list = fruitsStorageStockService.findListBySpec(fruitsStorageStockParam,user.getOperateId());
        return ResponseData.success(list);
    }

    /**
     *损耗接口
     */
    @RequestMapping("/empty")
    @ResponseBody
    public ResponseData empty(FruitsStorageStockParam fruitsStorageStockParam) {
    	fruitsStorageStockParam.setStockstate("已损耗");
        this.fruitsStorageStockService.update(fruitsStorageStockParam);
        return ResponseData.success();
    }

    /**
     * 报废接口
     */
    @RequestMapping("/scrap")
    @ResponseBody
    public ResponseData scrap(FruitsStorageStockParam fruitsStorageStockParam) {
    	fruitsStorageStockParam.setStockstate("已报废");
        this.fruitsStorageStockService.update(fruitsStorageStockParam);
        return ResponseData.success();
    }

    /**
     * 查询客户
     */
    @RequestMapping("/findfruitsBasicCustomer")
    @ResponseBody
    public ResponseData findfruitsBasicCustomer(FruitsBasicCustomerParam fruitsBasicCustomerParam) {
    	User user = userAop.getUser();
    	fruitsBasicCustomerParam.setDeptId(user.getDeptId());
        return ResponseData.success(fruitsBasicCustomerService.findListBySpec(fruitsBasicCustomerParam,user.getOperateId()));
    }

    /**
     * 库存分析
     */
    @ResponseBody
    @RequestMapping("/analysislist")
    public LayuiPageInfo analysislist(FruitsOrderPutParam fruitsOrderPutParam) {
    	User user = userAop.getUser();
    	fruitsOrderPutParam.setDeptId(user.getDeptId());
        return this.fruitsOrderPutService.findAnalysisPageBySpecApplets(fruitsOrderPutParam,user.getOperateId());
    }

}
